package com.autonavi.yunda.yunji.core.service;

import com.autonavi.yunda.yunji.common.thread.ThreadPoolMonitor;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.MDC;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.util.DigestUtils;

import java.util.UUID;

import static com.autonavi.yunda.yunji.common.constant.CommonConstant.MDC_TRACE_ID;

/**
 * @author cizhong.wcs
 * @date 2022/6/21 14:50
 */
@Slf4j
//@Component
//@EnableScheduling
public class CoreScheduledService {
    //    @Autowired
    ThreadPoolMonitor monitor;

    @Scheduled(cron = "0 0/1 * * * *")
    public void monitorThreadInfo() {
        MDC.put(MDC_TRACE_ID, DigestUtils.md5DigestAsHex(UUID.randomUUID().toString().getBytes()));
        //todo 后续可以把监控加到tsdb
        monitor.getThreadInfo().forEach(info -> log.info(info.toString()));
        MDC.remove(MDC_TRACE_ID);
    }
}
